<?php
class Page{
	/*
     * 分页
	 * $count 总条数
	 * $arr 搜索的字段
     * */
    public function pageC($count=20,$arr=['start','end']){
        $in=$_GET;
        $where=[];
        foreach ($arr as $v){
            if(!empty($in[$v])) $where[$v]=$in[$v];
        }
        $path=$_SERVER['PATH_INFO'];
        $page=$_GET['page']?$_GET['page']:1;
        //if(!empty($get['page'])) unset($get['page']);
        $search = http_build_query($where);
        $html='';
        $last='';//上一页
        $next='';//下一页
        $ellipsisS='';//省略
        $ellipsisE='';//省略
        for($i=1;$i<=$count;$i++){
            if($page>1){
                if(!$last) $last.='<li><a href="'.$path.'?page='.($page -1).'&'.$search.'">上一页</a></li>';
            }else  if(!$last) $last.='<li class="disabled"><span>上一页</span></li>';

            if($page == $count){
                if(!$next) $next='<li class="disabled"><span>下一页</span></li>';
            }else{
                if(!$next) $next.='<li><a href="'.$path.'?page='.($page+1).'&'.$search.'">下一页</a></li>';
            }


            if($i == $page) $html.='<li class="active"><span>'.$i.'</span></li>';
            else{
                if($count > 10){
                    if($i > 3){
                        if(abs($i-$page)>1){
                            if(!$ellipsisS) {
                                $ellipsisS.='<li class="disabled"><span>...</span></li>';
                                $html .= $ellipsisS;
                            }
                            if($i-$page>=2){
                                if(($count-$i) >= 3){
                                    if(!$ellipsisE) {
                                        $ellipsisE.='<li class="disabled"><span>...</span></li>';
                                        $ex=substr($html,-strlen($ellipsisE),strlen($ellipsisE));
                                        if($ex != $ellipsisE) $html .= $ellipsisE;
                                    }
                                }else{
                                    $html.='<li><a href="'.$path.'?page='.$i.'&'.$search.'">'.$i.'</a></li>';
                                }
                            }
                        }else{
                            $html.='<li><a href="'.$path.'?page='.$i.'&'.$search.'">'.$i.'</a></li>';
                        }
                    }else{
                        $html.='<li><a href="'.$path.'?page='.$i.'&'.$search.'">'.$i.'</a></li>';
                    }
                }else{
                    $html.='<li><a href="'.$path.'?page='.$i.'&'.$search.'">'.$i.'</a></li>';
                }
            }
        }
        $page='<ul class="pagination">'.$last.$html.$next.'</ul>';
        return $page;
    }
	
	//分页css样式
	/*<style>
    .pagination{
        display: inline-block;
        padding-left: 0;
        margin: 20px 10px;
        border-radius: 4px;
    }
    .pagination>li {
        display: inline;
    }
    .pagination>li:first-child>a, .pagination>li:first-child>span {
        margin-left: 0;
        border-top-left-radius: 4px;
        border-bottom-left-radius: 4px;
    }
    .pagination>li>a, .pagination>li>span {
        position: relative;
        float: left;
        padding: 6px 12px;
        margin-left: -1px;
        line-height: 1.42857143;
        color: #337ab7;
        text-decoration: none;
        background-color: #fff;
        border: 1px solid #ddd;
    }
    .pagination>li>a:hover,.pagination>li>span:hover{
        background-color:#ddd;
    }
    .pagination>li>a.current{
        background-color:rgb(221,221,221);
    }

    tbody tr:hover{background: #eee}
    .pagination>li.active>span{background: #ddd !important;}
</style>*/
}